package com.definesys.smecrailtransit.module.SiteDetails.adapter;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.definesys.smecrailtransit.R;
import com.definesys.smecrailtransit.base.SmecBaseRecyclerViewHolder;
import com.definesys.smecrailtransit.databinding.ItemSiteParamAchievesBinding;
import com.definesys.smecrailtransit.module.SiteDetails.bean.EleParamentBean;
import com.definesys.smecrailtransit.module.SiteDetails.dialog.SiteParamDialog;
import com.definesys.smecrailtransit.utils.CommonUtils;

import java.util.ArrayList;

/**
 * Created by cjy on 2018/3/7.
 */

public class SiteDetailsParaAdapter extends RecyclerView.Adapter<SmecBaseRecyclerViewHolder> {
    private ArrayList<EleParamentBean> list;
    private Context mContext;

    public SiteDetailsParaAdapter(Context context){
        list = new ArrayList<>();
        mContext = context;
    }

    @Override
    public SmecBaseRecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ItemSiteParamAchievesBinding itemSiteParamAchievesBinding= DataBindingUtil.inflate(LayoutInflater.from(mContext), R.layout.item_site_param_achieves,parent,false);
        SmecBaseRecyclerViewHolder smecBaseRecyclerViewHolder=new SmecBaseRecyclerViewHolder(itemSiteParamAchievesBinding.getRoot());
        smecBaseRecyclerViewHolder.setViewType(viewType);
        smecBaseRecyclerViewHolder.setBinding(itemSiteParamAchievesBinding);
        return smecBaseRecyclerViewHolder;
    }

    @Override
    public void onBindViewHolder(SmecBaseRecyclerViewHolder holder, int position) {
        holder.setIsRecyclable(false);
        ItemSiteParamAchievesBinding itemSiteParamAchievesBinding = (ItemSiteParamAchievesBinding) holder.getBinding();

        itemSiteParamAchievesBinding.code.setText(list.get(position).getEleCode());
        itemSiteParamAchievesBinding.contractNo.setText(list.get(position).getSerialNumber());
        itemSiteParamAchievesBinding.item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SiteParamDialog dialog = new SiteParamDialog(mContext,R.style.project_back,list.get(position));
                dialog.show();
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public ArrayList<EleParamentBean> getList() {
        return list;
    }

    public void setList(ArrayList<EleParamentBean> list) {
        if(CommonUtils.notEmpty(list)) {
            this.list = list;
        }else {
            this.list=new ArrayList<>();
        }
    }
}
